package top.continew.admin.generator.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import top.continew.admin.generator.mapper.TaskTodoUploadMapper;
import top.continew.admin.generator.model.entity.TaskTodoUploadDO;
import top.continew.admin.generator.model.query.TaskTodoUploadQuery;
import top.continew.admin.generator.model.req.TaskTodoUploadReq;
import top.continew.admin.generator.model.resp.TaskTodoUploadDetailResp;
import top.continew.admin.generator.model.resp.TaskTodoUploadResp;
import top.continew.admin.generator.service.TaskTodoUploadService;
import top.continew.starter.extension.crud.service.BaseServiceImpl;

import java.util.List;

/**
 * 待办事项附件业务实现
 *
 * @author kellen
 * @since 2025/07/30
 */
@Service
@RequiredArgsConstructor
public class TaskTodoUploadServiceImpl extends BaseServiceImpl<TaskTodoUploadMapper, TaskTodoUploadDO, TaskTodoUploadResp, TaskTodoUploadDetailResp, TaskTodoUploadQuery, TaskTodoUploadReq> implements TaskTodoUploadService {

    @Override
    public List<TaskTodoUploadResp> listByTaskTodoId(Long taskTodoId) {
        List<TaskTodoUploadDO> uploads = this.list(
            new LambdaQueryWrapper<TaskTodoUploadDO>()
                .eq(TaskTodoUploadDO::getTaskTodoId, taskTodoId)
                .orderByAsc(TaskTodoUploadDO::getCreateTime)
        );

        return uploads.stream().map(u->{
            TaskTodoUploadResp taskTodoUploadResp = new TaskTodoUploadResp();
            BeanUtils.copyProperties(u,taskTodoUploadResp);
            return  taskTodoUploadResp;
        }).toList();
    }

    @Override
    public void deleteByTaskTodoId(Long taskTodoId) {
        this.remove(new LambdaQueryWrapper<TaskTodoUploadDO>()
            .eq(TaskTodoUploadDO::getTaskTodoId, taskTodoId));
    }
}